<?php

namespace app\api\controller;

 
use app\common\controller\ApiController;
use think\App;
use think\facade\Env;
use think\facade\Db;

class Index extends ApiController
{

    protected $noNeedLogin= ['get_navigation_list','get_recommended_attractions','get_img'];
    protected $mustLogin = [];

 
    //导航列表
    public function get_navigation_list(){
        $list=Db::name('navigation')->order('id asc')->select();
        $this->success('获取成功',$list);
    }
    //首页图片
    public function get_img(){
        $param = $this->request->param();
        if (empty($param['type'])) {
            $this->error('未找到指定类型');
        }
        if($param['type'] == 1){
            $list = Db::name('banner')->where('type',$param['type'])->field('id,type,img,add_time,imgurl')->select();
        }else{
            $list = Db::name('banner')->where('type',$param['type'])->field('id,type,img,add_time')->select();
        }
        
        $this->success('获取成功',$list);
    } 
    //景点列表
    public function get_recommended_attractions(){
        $param = $this->request->param();
        if (empty($param['rsc'])) {
            $this->error('未找到指定类型');
        }
        if($param['rsc'] == 1){
            $list=Db::name('scenic_spot')->where('isindex',1)->where("type","in",[1,3,4])->order('sort asc')->select();
        }else{
            $num = isset($param['num']) ? $param['num'] : 10000;
            $list=Db::name('scenic_spot')->where("type","in","1,3,4")
                ->order('sort asc')
                ->paginate($num)->each(function($item){
                    $item["scenic_img"] = explode("|",$item['scenic_img']);
                    return $item;
                });
        }
        $this->success('获取成功',$list);
    }

    //景点详情
    public function attractions_detail(){
        $param = $this->request->param();
        if (empty($param['id'])) {
            $this->error('未找到指定景点');
        }
        $list=Db::name('scenic_spot')->where('id',$param['id'])->find();
        $list['scenic_img'] = explode('|',$list['scenic_img']);
        $list['content'] = html_entity_decode($list['content']);
        $list['content'] = str_replace(array("\r", "\n\n", "\s", "\t", "\n"), '<br/>', $list['content']);
        $this->success('获取成功',$list);
    }
 

}
